package com.online.controller;

import com.online.entity.*;
import com.online.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.online.pojo.Course;

import com.github.pagehelper.Page;

import java.util.List;

/**
 * 
 */
@RestController
@RequestMapping("/Course")
public class CourseController {
    @Autowired
    private CourseService iCourseService;


    /**
    * 查询全部
    * @param
    * @return
    */
    @GetMapping("/selectAll")
    public
    Result< List<Course> > selectAll(){
        return Result.ok("查询成功",iCourseService.selectAll());
    }


    /**
     * 条件查询
     * @param iCourse
     * @return
     */
    @PostMapping("/selectList")
    public Result< List<Course> > select(@RequestBody Course iCourse){
        return Result.ok("条件查询成功",iCourseService.selectList(iCourse));
    }

    /**
     * 新增
     * @param iCourse
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Course iCourse){
        iCourseService.insert(iCourse);
        return Result.ok("新增成功");
    }


    /**
     * 删除
     * @param ids
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam String ids){
        iCourseService.delete(ids);
        return Result.ok("删除成功");
    }


    /**
     * 修改
     * @param iCourse
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Course iCourse){
        iCourseService.update(iCourse);
        return Result.ok("修改成功");
    }

    /**
    * 分页搜索实现
    * @param page 默认值1
    * @param size 默认值10
    * @return
    */
    @GetMapping(value = "/pageAll" )
    public Result pageAll(@RequestParam(defaultValue = "1")  Integer page, @RequestParam(defaultValue = "10") Integer size){
    Page<Course> pageList = iCourseService.pageAll(page, size);
        PageResult pageResult=new PageResult(pageList.getTotal(),pageList.getResult());
        return Result.ok("查询成功",pageResult);
    }

    /**
    * 分页条件搜索实现
    * @param iCourse
    * @param page
    * @param size
    * @return
    */
    @GetMapping(value = "/pageList" )
    public Result pageList(@RequestBody Course iCourse,@RequestParam(defaultValue = "1")  Integer page, @RequestParam(defaultValue = "10") Integer size){
    Page<Course> pageList = iCourseService.pageList(iCourse,page, size);
        PageResult pageResult=new PageResult(pageList.getTotal(),pageList.getResult());
        return Result.ok("查询成功",pageResult);
    }
}




